import App from "./App";
import {
  renderWithQiankun,
  qiankunWindow,
} from "vite-plugin-qiankun/dist/helper";
import ReactDOM from "react-dom/client";

let app: any;

function render() {
  app = ReactDOM.createRoot(document.getElementById("app")!);
  app.render(<App />);
}

// 判断是否独立运行
if (!qiankunWindow.__POWERED_BY_QIANKUN__) {
  render();
}

renderWithQiankun({
  bootstrap() {
    console.log("bootstrap");
  },
  mount(props) {
    console.log("React子应用挂载", props);
    render();
  },
  unmount() {
    if (app && typeof app.unmount === "function") {
      app.unmount();
      console.log("react子应用卸载");
    }
  },
  update() {
    console.log("更新");
  },
});
